# -*- coding: utf-8 -*-
"""
@Time ： 2023/4/7 22:39
@Auth ： 叶东宇
@File ：doubleReverse.py
"""

from Chain.Chain import *
from Chain.Reverse_Chain.reverse_chain import reverse_chain


def double_reverse(chain):
    # 零元素
    if chain.head.next is None:
        return reverse_chain(chain)
    # 一个元素
    elif chain.head.next.next is None:
        return reverse_chain(chain)
    # 两个及两个以上的元素
    else:
        el = chain.head
        first = chain.head.next.next
        last = chain.head.next
        while first is not None:
            last.next = first.next
            first.next = last
            el.next = first
            # 交换顺序
            tmp = first
            first = last
            last = tmp
            # 移动指针
            if first.next is not None and first.next.next is not None:
                first = first.next.next
                last = last.next.next
                el = el.next.next
            else:
                break
        return chain



if __name__ == "__main__":
    lis = [6,9,0,7,5,8]
    chain = create_chain_head(lis)
    print(chain.traverse())
    chain_ = double_reverse(chain)
    print(chain_.traverse())
